package com.bw.doctor.service.impl;
/**
 * @Author：尚志豪
 * @Package：com.bw.doctor.service.impl
 * @Project：doudi-group2-shixun-02
 * @name：RapidConsultationServiceImpl
 * @Date：2025/2/27 10:09
 */

import com.bw.domain.Doctor;
import com.bw.domain.Register;
import com.bw.domain.SBodyPortraitMiddleSymptom;
import com.bw.domain.SSymptom;
import com.bw.doctor.mapper.RapidConsultationMapper;
import com.bw.doctor.service.RapidConsultationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: doudi-group2-shixun-02
 * @description: 快速问诊业务逻辑
 * @author: CuiFu Bo
 * @create: 2025-02-27 10:09
 **/
@Service
public class RapidConsultationServiceImpl implements RapidConsultationService
{
    @Autowired
    private RapidConsultationMapper consultationMapper;
    /**
     * 通过部位查看对应的病症
     */
    @Override
    @Transactional
    public List<SSymptom> lookAtTheCorrespondingDiseaseByLocation(Long id) {
        // 获取中间表
        List<SBodyPortraitMiddleSymptom> symptomList = consultationMapper.lookAtTheCorrespondingDiseaseByLocation(id);

        List<Long> ids = new ArrayList<>();
        for (SBodyPortraitMiddleSymptom middleSymptom : symptomList) {
            ids.add(middleSymptom.getSymptomId());
        }
        System.out.println("ids: " + ids);
        // 获取症状列表
        List<SSymptom> sSymptomList = consultationMapper.symptomList(ids);

        return sSymptomList;
    }
    /**
     * 通过病症查到对应的医生
     */
    @Override
    public List<Doctor> weCanTraceTheSymptomsToTheDoctor(String tag) {
        return consultationMapper.weCanTraceTheSymptomsToTheDoctor(tag);
    }

    /**
     * 挂号
     * @param register
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void register(Register register) {
        //根据医生姓名获取医生id
        register.setDoctorId(consultationMapper.getDoctorIdByName(register.getDoctorName()));
        register.setRegisterStatus(0);
        consultationMapper.register(register);
    }

    /**
     * 取消挂号
     * @param register
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void cancelRegister(Register register) {
        register.setDoctorId(consultationMapper.getDoctorIdByName(register.getDoctorName()));
        consultationMapper.cancelRegister(register);
    }

    /**
     * 获取挂号数据
     * @param register
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer getRegisterData(Register register) {
        register.setDoctorId(consultationMapper.getDoctorIdByName(register.getDoctorName()));
        Integer registerStatus = consultationMapper.getRegisterData(register);
        return registerStatus;
    }
}
